package com.sjziei;

import java.util.Scanner;

public class StudentManager {

    private StudentService ss = new StudentService();
    public void start(){
        Scanner scanner = new Scanner(System.in);
        while (true){
            System.out.println("1.添加学生信息");
            System.out.println("2.按学号查找学生信息");
            System.out.println("3.按学号删除学生信息");
            System.out.println("9.显示所有学生信息");
            System.out.println("0.退出");
            String selStr = scanner.nextLine();
            char selChar = selStr.charAt(0);
            if(selChar == '1'){
                this.add();
            }else if(selChar == '0'){
                break;
            }else if(selChar == '9'){
               this.display();
            }else if(selChar == '2'){
                this.findByStuNo();
            }else if(selChar == '3'){
                this.delete();
            }
        }
    }

    private void delete() {
        System.out.println("请输入要删除的学生学号：");
        Scanner scanner = new Scanner(System.in);
        String stuNo = scanner.nextLine();
        Student student = ss.deleteByStuNo(stuNo);
        if(student != null){
            System.out.println("已经删除的学生信息：");
            System.out.println(student.toString());
        }else {
            System.out.println("没有找到学号为 " + stuNo + " 的学生，无法删除");
        }
    }

    private void findByStuNo() {
        System.out.println("请输入要查询的学生学号：");
        Scanner scanner = new Scanner(System.in);
        String stuNo = scanner.nextLine();
        Student student = ss.findByStuNo(stuNo);
        if(student != null){
            System.out.println("查询到的学生信息：");
            System.out.println(student.toString());
        }else {
            System.out.println("没有找到学号为 " + stuNo + " 的学生");
        }
    }

    private void add(){
 /*       Student student = ss.createStudent();
        students.append(student);*/
        ss.addStudent();
    }
    private void display(){
 /*       for(int i=0; i<students.getLength(); i++){
            System.out.println(students.get(i));
        }*/
        ss.display();
    }
}
